package com.controller;

import com.pojo.Dept;
import com.pojo.Result;
import com.service.DeptService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


//部门管理控制器
@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {
//    private  static Logger log = (Logger) LoggerFactory.getLogger(DeptController.class);


    //查询部门数据
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result list(){
        log.info("查询所有部门信息");

        List<Dept> deptList =deptService.list();

        return Result.success(deptList);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除部门{}",id);
        deptService.delete(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("添加部门{}",dept);
        deptService.add(dept);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody Dept dept){
        log.info("修改部门: {}", dept);
        deptService.update(dept);
        return Result.success();
    }

}
